import re
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field, validator, EmailStr, IPvAnyAddress

from common.utils import is_empty

from enum import Enum

class DelBaseModel(BaseModel):
    uuid: int = Field(..., description="数据的uuid")



class PostNoticeUser(BaseModel):
    name: str = Field(..., description="通知人姓名")
    telephone: str = Field(..., description="通知人手机号码")
    mailbox: EmailStr = Field(..., description="通知邮箱地址")
    comment: Optional[str] = Field("", description="通知人说明")

    @validator('telephone')
    def telephone_choices(cls, v):
        pattern = re.compile(r'^1[356789]\d{9}$')
        if re.search(pattern, str(v)) is None:
            raise ValueError('telephone incorrect format')
        return v


class PutNoticeUser(PostNoticeUser):
    uuid: int = Field(..., description="通知人数据uuid")



class PostNoticeTeam(BaseModel):
    name: str = Field(..., description="通知组的名称")
    comment: Optional[str] = Field("", description="通知组的说明")
    users_uuid: List[int] = Field(..., description="通知组内有哪些通知人的uuid")


class PutNoticeTeam(BaseModel):
    uuid: int = Field(..., description="通知组数据uuid")
    comment: Optional[str] = Field("", description="通知组的说明")
    users_uuid: List[int] = Field(..., description="通知组内有哪些通知人的uuid")


class PostDepartmentInfo(BaseModel):
    name: str = Field(..., description="部门名称")
    notice_teams_uuid: List[int] = Field(..., description="主机组关联的通知组uuid")
    comment: Optional[str] = Field("", description="部门说明")


class PutDepartmentInfo(BaseModel):
    uuid: int = Field(..., description="部门数据uuid")
    notice_teams_uuid: List[int] = Field(..., description="主机组关联的通知组uuid")
    comment: Optional[str] = Field("", description="部门说明")